package com.jp.knowledge.activity;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jiayen.util.ToasUtil;
import com.jp.knowledge.R;
import com.jp.knowledge.logic.PersonLogic;
import com.jp.knowledge.model.VipGrade;
import com.jp.knowledge.my.activity.VipBuyActivity;
import com.jp.knowledge.util.ImageLoadUtil;
import com.jp.knowledge.wxapi.WXPayEntryActivity;
import com.tencent.mm.opensdk.modelbase.BaseResp;

import org.xutils.view.annotation.ViewInject;

/**
 * Created by 528787067@qq.com on 2017/6/27.
 */

public class PayPermissionActivity extends VipBuyActivity {

	@ViewInject(R.id.list_view)
	private RecyclerView listView;
	@ViewInject(R.id.pay_link_view)
	private LinearLayout payLinkView;
	@ViewInject(R.id.pay_linkIcon)
	private ImageView payLinkIcon;
	@ViewInject(R.id.pay_linkTitle)
	private TextView payLinkTitle;
	@ViewInject(R.id.pay_way_name)
	private TextView payWayName;

	private String linkId;
	private String linkIcon;
	private String linkTitle;
	private int payMoney;

	@Override
	protected void init() {
		super.init();
		listView.setVisibility(View.GONE);
		payLinkView.setVisibility(View.VISIBLE);

		linkId = getIntent().getStringExtra("linkId");
		linkIcon = getIntent().getStringExtra("linkIcon");
		linkTitle = getIntent().getStringExtra("linkTitle");
		payMoney = getIntent().getIntExtra("payMoney", 0);
		ImageLoadUtil.load(mContext, linkIcon, payLinkIcon);
		payLinkTitle.setText(linkTitle);
		curVipGrade = new VipGrade();
		curVipGrade.setPackagePrice(payMoney);
		curVipGrade.setPackageId(linkId);

		payWayName.setText("购买内容");
		setVipPrice();
	}

	@Override
	protected void getData() {

	}

	@Override
	protected void onPayFinish(Context context, Intent intent){
		String action = intent.getAction();
		if(WXPayEntryActivity.WECHAT_PAY.equals(action)){
			int errCode = intent.getIntExtra(WXPayEntryActivity.WECHAT_PAY_ERR_CODE, -1);
			if(errCode == BaseResp.ErrCode.ERR_OK)
				finish();
		}
	}

	@Override
	protected void openWeChatPay(int money){
		payLogic.pay(money,application.getUserData().getUuid(),"00000000",24,"支付费用",1010,curVipGrade.getPackageId());
	}
}
